package demo;

/**
 * 建造者模式
 * 将一个复杂对象的构建与他的表示分离，使得同样的过程可以创建不同的表示。
 * @author ZhouWeiBo
 * @create 2022/6/7
 */
@SuppressWarnings("all")
public class House {
    private Wall wall;
    private Door door;
    private Window window;
    private Floor floor;

    // ........省略一大堆Get、Set..........
    // 真实环境中可以用Lombok的@Builder

    public House(HouseBuilder houseBuilder){
        this.door = houseBuilder.door;
        this.wall = houseBuilder.wall;
        this.floor = houseBuilder.floor;
        this.window = houseBuilder.window;
    }
    static final class HouseBuilder{
        private Wall wall;
        private Door door;
        private Window window;
        private Floor floor;

        public HouseBuilder buildWall(Wall wall) {
            this.wall = wall;
            return this;
        }

        public HouseBuilder buildDoor(Door door) {
            this.door = door;
            return this;
        }

        public HouseBuilder buildWindow(Window window) {
            this.window = window;
            return this;
        }

        public HouseBuilder buildFloor(Floor floor) {
            this.floor = floor;
            return this;
        }

        public House build(){
            return new House(this);
        }
    }

}
